//
//  KYLeftView.m
//  kuaiyi
//
//  Created by 杨亮 on 16/3/12.
//  Copyright © 2016年 kuaiyi. All rights reserved.
//

#import "KYLeftView.h"
#import "Header.h"
#import <Masonry.h>

@interface KYLeftView ()
@property (nonatomic, strong)UIImageView *topView;
@property (nonatomic, strong)UIImageView *nameImage;
@property (nonatomic, strong)UIButton *loginBtn;
@property (nonatomic, strong)UIButton *registBtn;
@end
@implementation KYLeftView
#pragma mark - 懒加载
-(UIImageView *)topView{
    if (!_topView) {
        _topView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nav"]];
    }
    return _topView;
}
-(UIImageView *)nameImage{
    if (!_nameImage) {
        _nameImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"name"]];
        _nameImage.layer.cornerRadius = 20;
        _nameImage.layer.masksToBounds = YES;
    }
    return _nameImage;
}
-(UIButton *)loginBtn{
    if (!_loginBtn) {
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"bk"] forState:UIControlStateNormal];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_loginBtn addTarget:self action:@selector(loginBtnKlick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}
-(UIButton *)registBtn{
    if (!_registBtn) {
        _registBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registBtn setBackgroundImage:[UIImage imageNamed:@"bk"] forState:UIControlStateNormal];
        [_registBtn setTitle:@"注册" forState:UIControlStateNormal];
        _registBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_registBtn addTarget:self action:@selector(registBtnKlick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _registBtn;
}
#pragma mark - 初始化方法
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUpUI];
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]];
    }
    return self;
}
#pragma mark - 设置UI
-(void)setUpUI{
    [self addSubview:self.topView];
    [self addSubview:self.nameImage];
    [self addSubview:self.loginBtn];
    [self addSubview:self.registBtn];
    self.topView.frame = CGRectMake(0, 0, ScreenWith, 134.5);
    CGFloat nameImageX = (drawerWidth - nameImageWith)/2;
    self.nameImage.frame = CGRectMake(nameImageX, 25, nameImageWith, nameImageWith);
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@80);
        make.height.equalTo(@25);
        make.top.equalTo(self.nameImage.mas_bottom).offset(10);
        make.right.equalTo(self.nameImage.mas_centerX).offset(-10);
    }];
    [self.registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@80);
        make.height.equalTo(@25);
        make.top.equalTo(self.nameImage.mas_bottom).offset(10);
        make.left.equalTo(self.nameImage.mas_centerX).offset(10);
    }];
}
#pragma mark - 按钮点击事件
-(void)loginBtnKlick{
//    NSLog(@"登录按钮点击");
    if ([self.delegate respondsToSelector:@selector(loginBtnKlick:)]) {
        [self.delegate loginBtnKlick:self];
    }
}
-(void)registBtnKlick{
//    NSLog(@"注册按钮点击");
    if ([self.delegate respondsToSelector:@selector(registBtnKlick:)]) {
        [self.delegate registBtnKlick:self];
    }
}
@end
